<!DOCTYPE html>
<html lang="en">
<head>
    <title>每周五销售预测填报</title>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="Cache-Control" content="no-store, must-revalidate">
    <meta http-equiv="expires" content="Wed, 26 Feb 1997 08:21:57 GMT">
    <meta http-equiv="expires" content="-1">
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="shortcut icon" href="/dist/img/icon.png" type="image/x-icon">
    <!-- Bootstrap 3.3.6 -->
    <link rel="stylesheet" href="/dist/plugins/bootstrap/css/bootstrap.min.css">
    <!--字体-->
    <link rel="stylesheet" href="/dist/css/font-awesome.min.css">
    <!--图标-->
    <link rel="stylesheet" href="/dist/css/ionicons.min.css">
    <!--插件样式-->
    <link href="/dist/plugins/ztree/css/zTreeStyle/zTreeStyle.css" rel="stylesheet"/>
    <!--OA主样式-->
    <link rel="stylesheet" href="/dist/css/OA.min.css?t=4a6c1b54">
    <link rel="stylesheet" href="/dist/css/skins/OA-skins.min.css?t=16f1e6f3">
    <style>
        .moduleName {
            height: 28px;
            line-height: 28px;
            font-size: 22px;
            border-bottom: 1px solid #ddd;
            text-align: center;

        }

        .tryStyle {
            width: 30px;
            height: 14px;
            line-height: 14px;
            font-size: 12px;
            /* top: 0; */
            right: 0;
            position: absolute;
            border-radius: 5px;
            margin-top: 1px;
            background: red;
            color: #fff;
            margin-right: -2px;
            transform: scale(0.8);
        }

        .nav-tabs-custom {
            padding: 10px 0;
            margin-bottom: 0;
            box-shadow: none;
            position: relative;
            overflow: hidden;
        }

        .infoReport {
            display: flex;
            justify-content: flex-start;
            text-align: left;
            margin-left: 10px;
        }

        .infoReport div {
            margin: 0 10px;
        }

        .lineOne {
            text-align: left;
        }

        .lineOne span {
            max-height: 20px;
            line-height: 20px;
            overflow: hidden;
            text-overflow: ellipsis;
            display: -webkit-box;
            -webkit-box-orient: vertical;
            -webkit-line-clamp: 1;
            text-align: left;
        }

        .lineOneNoMore {
            text-align: left;
        }

        .lineOneNoMore span {
            max-height: 20px;
            line-height: 20px;
            overflow: hidden;
            text-overflow: ellipsis;
            display: -webkit-box;
            -webkit-box-orient: vertical;
            -webkit-line-clamp: 1;
            text-align: left;
        }

        .mScrollBox {
            float: left;
            position: relative;
        }

        .imgStyle {
            width: 300px;
            height: 400px;
        }

        .div-td-content-more {
            position: absolute;
            height: auto;
            z-index: 999;
            line-height: 20px;
            background-color: #d3e8fd;
            padding: 8px 6px;
            border: 1px solid #e8e8ea;
            display: none;
        }

        .div-td-content-more i {
            width: 15px;
            height: 12px;
            background: url("/dist/img/more-icon.png");
            position: absolute;
            left: 50px;
            top: -12px;
        }

        .templateStyle {
            border: 1px solid #ddd;
            /*margin-bottom: 10px;*/
            padding: 0 10px;
        }

        .table > thead > tr > th {
            padding: 0;
        }

        .table > tbody > tr > td {
            position: relative;
        }

        .selectBox {
            height: 25px;
            margin-bottom: 10px;
        }

        .span-a-btn {
            position: absolute;
            right: 10px;
            top: 18px;
        }

        .table-width {
            width: 35%;
            float: left;
        }

        .remark {
            margin-left: 3px;
        }

        .left {
            width: 170px;
            float: left;
        }

        .right {
            margin-left: 180px;
        }

        .btnList {
            position: fixed;
            bottom: 15px;
            left: 45%;
        }

        table td.td-tanZongStyle input[type="text"] {
            box-shadow: rgb(51, 51, 51) 1px 1px 4px inset;
            width: 100%;
            height: 100%;
            padding-left: 4px;
            text-align: center;
        }

        table td.td-tanZongStyle {
            padding: 1px !important;
            text-align: center !important;
        }
    </style>
</head>
<body>
<section class="content" id="app" v-cloak>
    <iframe id="ifExprot" style="width:0px;height:0px;display: none;" frameborder="0"></iframe>
    <div class="div-td-content-more"><i></i></div>
    <div class="row">
        <div class="left" id="inboxGroup" id="divLeft">
            <div class="box-body no-padding box-border iframeH" style="overflow-y: auto;background: #f7f8fa;">
                <ul class="ztree" id="ztree"></ul>
            </div>
        </div>
        <div class="right">
            <template v-if="main.status=='-1'&&roleName!='大区经理'">
                <div class="templateStyle iframeH" style="overflow-y: auto;">
                    <div class="nav-tabs-custom">
                        <div class="moduleName">该大区经理本周五未填写销售预测填报({{getWeek(main.day,0)}}--{{getWeek(main.day,6)}})
                        </div>
                    </div>
                </div>
            </template>
            <template v-else-if="main.status=='-2'&&sub.length==0">
                <div class="templateStyle iframeH" style="overflow-y: auto;">
                    <div class="nav-tabs-custom">
                        <div class="moduleName">该公司本周五未填写销售预测填报({{getWeek(main.day,0)}}--{{getWeek(main.day,6)}})
                        </div>
                    </div>
                </div>
            </template>
            <template v-else>
                <div class="templateStyle iframeH" style="overflow-y: auto;">
                    <div class="nav-tabs-custom">
                        <div class="moduleName">每周五销售预测填报({{getWeek(main.day,0)}}--{{getWeek(main.day,6)}})</div>
                    </div>
                    <table class="table table-bordered text-center table-width">
                        <thead>
                        <tr>
                            <th style="width: 25%">机型</th>
                            <th style="width: 25%">{{jqDate(main.firstMonth)}}</th>
                            <th style="width: 25%">{{jqDate(main.secondMonth)}}</th>
                            <th style="width: 25%">{{jqDate(main.thirdMonth)}}</th>
                        </tr>
                        </thead>
                        <tbody>
                        <tr v-for="(item,i) in sub">
                            <td>{{item.modelName}}</td>
                            <td class="td-tanZongStyle">
                                <input type="text" v-model="item.firstMonth" @input="hq(item)"
                                       v-if="(main.status==-1||main.status==2)&&roleName=='大区经理'">
                                <span v-else
                                      style="text-align: center;">{{item.firstMonth==0?'':item.firstMonth}}</span>
                            </td>
                            <td class="td-tanZongStyle">
                                <input type="text" v-model="item.secondMonth" @input="hq(item)"
                                       v-if="(main.status=='-1'||main.status=='2')&&roleName=='大区经理'">
                                <span v-else
                                      style="text-align: center;">{{item.secondMonth==0?'':item.secondMonth}}</span>
                            </td>
                            <td class="td-tanZongStyle">
                                <input type="text" v-model="item.thirdMonth" @input="hq(item)"
                                       v-if="(main.status=='-1'||main.status=='2')&&roleName=='大区经理'">
                                <span v-else
                                      style="text-align: center;">{{item.thirdMonth==0?'':item.thirdMonth}}</span>
                            </td>
                        </tr>
                        <tr>
                            <td>本周预测</td>
                            <td>{{getAll.firstMonthYuce}}</td>
                            <td>{{getAll.secondMonthYuce}}</td>
                            <td>{{getAll.thirdMonthYuce}}</td>
                        </tr>
                        <tr>
                            <td>上周预测</td>
                            <td>{{main.firstMonthBef}}</td>
                            <td>{{main.secondMonthBef}}</td>
                            <td>{{main.thirdMonthBef}}</td>
                        </tr>
                        <tr>
                            <td>差距</td>
                            <td>{{Math.abs(Number(getAll.firstMonthYuce)-Number(main.firstMonthBef))}}</td>
                            <td>{{Math.abs(Number(getAll.secondMonthYuce)-Number(main.secondMonthBef))}}</td>
                            <td>{{Math.abs(Number(getAll.thirdMonthYuce)-Number(main.thirdMonthBef))}}</td>
                        </tr>
                        <tr>
                            <td>实际销售台数</td>
                            <td colspan="3" class="td-tanZongStyle">
                                <input type="text" v-model="main.actualSaleRemark"
                                       v-if="(main.status=='-1'||main.status=='2')&&roleName=='大区经理'">
                                <span v-else>{{main.actualSaleRemark==0?'':main.actualSaleRemark}}</span>
                            </td>
                        </tr>
                        </tbody>
                    </table>
                    <div class="remark" style="float: left;">
                        <p>填写说明：</p>
                        <p>1、此表每周五由大区经理填写：已售设备、截止到本月末及未来两个月的销售预测；</p>
                        <p>2、本周有成交的，将成交机型*台数填写到“实际销售台数”；</p>
                        <p>3、销售总监审核无误后由销售管理经理试用销售部公共邮箱发送给武帅、张驰，抄送给潘奇、曹国玉、贾贤达、谈总。</p>
                    </div>
                    <div class="btnList">
                        <input type="button" style="margin-left:20px;" value="通过" class="btn btn-primary btn-sm"
                               @click="goClick('tongGuo')" v-if="main.status==0&&main.auditorId==list.userId">
                        <input type="button" style="margin-left:20px;" value="驳回" class="btn btn-primary btn-sm"
                               @click="goClick('boHui')" v-if="main.status==0&&main.auditorId==list.userId">
                        <input type="button" style="margin-left:20px;" value="提交" class="btn btn-primary btn-sm"
                               @click="goClick('tiJiao')" v-if="(main.status==-1||main.status==2)&&roleName=='大区经理'">
                        <input type="button" style="margin-left:20px;" class="btn btn-primary btn-sm" value="导出"
                               @click="exportExcel()" v-if="(main.status==1||main.status==-2)&&roleName!='大区经理'">

                        <!--<a href="javascript:void(0);" @click="goClick('tongGuo')"-->
                        <!--style="color:#2a8cec;cursor: pointer;text-align: center"-->
                        <!--v-if="main.status==0&&main.auditorId==list.userId">通过</a>-->
                        <!--<a href="javascript:void(0);" @click="goClick('boHui')"-->
                        <!--style="color:#2a8cec;cursor: pointer;text-align: center"-->
                        <!--v-if="main.status==0&&main.auditorId==list.userId">驳回</a>-->
                        <!--<a href="javascript:void(0);" @click="goClick('tiJiao')"-->
                        <!--style="color:#2a8cec;cursor: pointer;text-align: center"-->
                        <!--v-if="(main.status==-1||main.status==2)&&roleName=='大区经理'">提交</a>-->
                    </div>
                </div>
            </template>
        </div>
    </div>
</section>
<script src="https://file.ggxqce.com/web/jquery-2.2.3.min.js"></script>
<!--插件JS-->
<script src="https://file.ggxqce.com/web/bootstrap.min.js"></script>
<!--框架已定义 JS-->
<script src="/dist/js/app_iframe.js?t=7e54a132"></script>
<!--oa自定义  JS-->
<script src="/dist/js/oa.js?t=63aed32f"></script>

<script src="https://file.ggxqce.com/web/vue.min.js"></script>
<script type="text/javascript" src="/dist/plugins/My97DatePicker/WdatePicker.js"></script>
<!--ztree组件所需js-->
<script type="text/javascript" src="/dist/plugins/ztree/js/jquery.ztree.all-3.5.min.js"></script>
<script type="text/javascript" src="/dist/plugins/ztree/js/jquery.ztree.exhide-3.5.js"></script>
<script src="/dist/plugins/webuploader-0.1.5/webuploader.min.js"></script>
<script type="text/javascript" src="/dist/js/pages/system/systemService.js"></script>
<script type="text/javascript" src="/dist/js/pages/common/commonService.js"></script>
<script type="text/javascript" src="/dist/js/pages/common/changeMoneyToChinese.js"></script>
<script type="text/javascript" src="/dist/plugins/print/print.js"></script>
<script type="text/javascript" src="/dist/plugins/lhgdialog/lhgdialog.min.js?self=true"></script>
<script type="text/javascript">
    var zTreeCallback = {
        showIcon: function (treeeId, treeNode) {
            return treeNode.isParent;
        },
        onClick: function (event, treeId, treeNode) {
            console.log(treeNode.type)
            var data = {};
            if (treeNode.type == "company") {
                app.list.companyId = treeNode.companyId;
                app.list.regionId = '';
                app.getSelect();
            }
            if (treeNode.type == "region") {
                app.list.companyId = treeNode.companyId;
                app.list.regionId = treeNode.regionId;
                app.getSelect();
            }
        },
//        beforeClick: function (treeId, treeNode, clickFlag) {
//            if (treeNode.level == 0) {
//                return false;
//            }
//        }
    };
    var zTreeSetting = {
        view: {
            showIcon: zTreeCallback.showIcon
        },
        data: {
            simpleData: {
                enable: true
            },
            keep: {
                parent: true
            }
        },
        callback: {
            onClick: zTreeCallback.onClick,
//            beforeClick: zTreeCallback.beforeClick
        }
    };

</script>
<script type="text/javascript">
    function refresh() {
        $.wyui.page.getByPage();
    }

    var app = new Vue({
        el: '#app',
        data: {
            main: {
                actualSaleRemark: '',
                firstMonth: '',
                secondMonth: '',
                thirdMonth: '',
                firstMonthBef: '',
                secondMonthBef: '',
                thirdMonthBef: '',
                day: new Date().Format("yyyy-MM-dd")
            },
            sub: [],
            getAll: {},
            companyName: '',
            regionName: '',
            roleName: getCurrentUser().roleName,
            beforeWeek: '',
            list: {
                companyId: '',
                regionId: '',
                userId: getCurrentUser().id,
                date: new Date().Format("yyyy-MM-dd"),
            }
        },
        methods: {
            hq: function (item) {
                console.log(item.firstMonth)
                var that = this;
                var num1 = 0;
                var num2 = 0;
                var num3 = 0;
                for (var i = 0; i < that.sub.length; i++) {
                    if (that.sub[i].firstMonth != '') {
                        num1 = num1 + Number(that.sub[i].firstMonth);
                    }
                    if (that.sub[i].secondMonth != '') {
                        num2 = num2 + Number(that.sub[i].secondMonth);
                    }
                    if (that.sub[i].thirdMonth != '') {
                        num3 = num3 + Number(that.sub[i].thirdMonth);
                    }
                }
                that.getAll.firstMonthYuce = num1;
                that.getAll.secondMonthYuce = num2;
                that.getAll.thirdMonthYuce = num3;
            },
            exportExcel: function () {
                var that = this;
                $('#ifExprot').attr('src', server.ip
                    + "/yuceMainController/getDownByCondition.json"
                    + '?companyId=' + that.list.companyId + "&&date=" + that.list.date + "&&regionId=" + that.list.regionId + "&&userId=" + that.list.userId + "&&title="
                );
                /*$('#ifExprot').attr('src', server.ip
                    + "/yuceMainController/getDownByCondition.json"
                    + '?companyId=' + that.list.companyId
                    + '&&date=' +that.list.date
                    + '&&regionId=' + that.list.regionId
                    + '&&userId=' + that.list.userId
                );*/
            },
            //获取合计
            getCount: function (arr, key) {
                var number = 0;
                for (var i = arr.length - 1; i >= 0; i--) {
                    number += (arr[i][key] && arr[i][key] != '-' ? arr[i][key] : 0)

                }
                return number;
            },
            //合并单元格
            tablesMergeCell: function (list) {
                for (field in list[0]) {
                    var k = 0;
                    while (k < list.length) {
                        list[k][field + 'span'] = 1;
                        list[k][field + 'dis'] = false;
                        for (var i = k + 1; i <= list.length - 1; i++) {
                            if (list[k][field] == list[i][field] && list[k][field] != '') {
                                list[k][field + 'span']++;
                                list[k][field + 'dis'] = false;
                                list[i][field + 'span'] = 1;
                                list[i][field + 'dis'] = true;
                            } else {
                                break;
                            }
                        }
                        k = i;
                    }
                }
                return list;
            },
            //初始化时间控件
            showDatePicker: function (e, type) {
                var that = this;
                WdatePicker({
                    onpicked: function (dp) {
                        that.selectParameter.day = dp.cal.getNewDateStr();
                        return true;
                    },
                    maxDate: new Date().Format("yyyy-MM-dd")//今天
                });
                $(e.target).blur();
            },
            getSelect: function () {
                var that = this;
                $.wyui.postMethod(urlConfig.yuce.select, that.list, function (data) {
                    console.log(data)
                    /*for(var i= 0;i<data.sub.length;i++){
                        if(data.sub[i].firstMonth=='0'){data.sub[i].firstMonth=''}
                        if(data.sub[i].secondMonth=='0'){data.sub[i].secondMonth=''}
                        if(data.sub[i].thirdMonth=='0'){data.sub[i].thirdMonth=''}
                    }*/
                    that.sub = data.sub;
                    that.main = data.main;
                    if (!that.main.day) {
                        that.main.day = new Date().Format("yyyy-MM-dd")
                        that.main.firstMonth = new Date().Format("yyyy-MM");
                        that.main.secondMonth = (that.getNextMonth(new Date().Format("yyyy-MM-dd"))).substring(0, 7)
                        that.main.thirdMonth = (that.getNextMonth(that.getNextMonth(new Date().Format("yyyy-MM-dd")))).substring(0, 7)
                    }
                    that.getAll.firstMonthYuce = that.getCount(that.sub, "firstMonth");
                    that.getAll.secondMonthYuce = that.getCount(that.sub, "secondMonth");
                    that.getAll.thirdMonthYuce = that.getCount(that.sub, "thirdMonth");
                });
            },
            //获取下个月
            getNextMonth: function (date) {
                var arr = date.split('-');
                var year = arr[0]; //获取当前日期的年份
                var month = arr[1]; //获取当前日期的月份
                var day = arr[2]; //获取当前日期的日
                var days = new Date(year, month, 0);
                days = days.getDate(); //获取当前日期中的月的天数
                var year2 = year;
                var month2 = parseInt(month) + 1;
                if (month2 == 13) {
                    year2 = parseInt(year2) + 1;
                    month2 = 1;
                }
                var day2 = day;
                var days2 = new Date(year2, month2, 0);
                days2 = days2.getDate();
                if (day2 > days2) {
                    day2 = days2;
                }
                if (month2 < 10) {
                    month2 = '0' + month2;
                }

                var t2 = year2 + '-' + month2 + '-' + day2;
                return t2;
            },
            save: function (type) {
                var that = this;
                that.main.status = type;
                that.main.day = that.getWeek(new Date().Format("yyyy-MM-dd"), 4);
                that.main.createUserId = getCurrentUser().id;
                that.main.companyId = that.list.companyId;
                that.main.bigRegionId = that.list.regionId;

                that.main.firstMonthYuce = that.getAll.firstMonthYuce,
                    that.main.secondMonthYuce = that.getAll.secondMonthYuce,
                    that.main.thirdMonthYuce = that.getAll.thirdMonthYuce,
                    that.main.firstMonthSub = Math.abs(Number(that.getAll.firstMonthYuce) - Number(that.main.firstMonthBef)),
                    that.main.secondMonthSub = Math.abs(Number(that.getAll.secondMonthYuce) - Number(that.main.secondMonthBef)),
                    that.main.thirdMonthSub = Math.abs(Number(that.getAll.thirdMonthYuce) - Number(that.main.thirdMonthBef)),
                    $.wyui.postMethod(urlConfig.yuce.save, trimRN({
                        main: that.main,
                        sub: that.sub,
                    }), function (data) {
                        alert("保存成功");
                        top.refreshTabByName("每周五销售预测", "no");
                        top.closeTabByPageId("zzht");
                    })
            },
            //获取周五
            getWeek: function (date, i) {
                var now = stringToDate(date)
                var firstDay = new Date(now - (now.getDay() - 1) * 86400000);
                firstDay.setDate(firstDay.getDate() + i);
                mon = Number(firstDay.getMonth()) + 1;
                day = firstDay.getDate()
                if (mon < 10) {
                    mon = "0" + mon
                }
                if (day < 10) {
                    day = "0" + day
                }
                return now.getFullYear() + "-" + mon + "-" + day;
            },

            //截取日期
            jqDate: function (dates) {
                var that = this;
                var num = dates.substring(5, 7);
                num = Number(num);
                return num + "月"
            },
            //获取树
            getTreeData: function () {
                var that = this;
                $.wyui.postMethod(urlConfig.yuce.getCompanyRegionTree, {
                    userId: getCurrentUser().id,
                    date: that.list.date,
                }, function (nodes) {
                    console.log(nodes)
                    for (var i = 0; i < nodes.length; i++) {
                        if (nodes[i].name == '重庆迎风') {
                            nodes.splice(i, 1);
                        }
                    }
                    that.treeObj = $.fn.zTree.init($("#ztree"), zTreeSetting, nodes);
                    var getNode = that.treeObj.getNodeByParam('type','region',null);
                    console.log(getNode)
                    if(getNode){
                        that.treeObj.selectNode(getNode)
                        that.list.companyId = getNode.companyId;
                        that.list.regionId = getNode.regionId;
                        that.userId = that.list.userId;
                        that.date = that.list.date;
                        that.getSelect();
                    }

                });
            },
            goClick: function (type) {
                var that = this;
                if (type == 'tiJiao') {
                    that.save(0);
                } else if (type == 'tongGuo') {
                    if (!confirm("确定要通过吗？")) {
                        return;
                    }
                    advise = '同意！';
                    $.wyui.postMethod(urlConfig.yuce.applyAudit, {
                            id: that.main.id,
                            auditFlag: 1,
                            advise: '同意!',
                            userId: that.list.userId
                        },
                        function (r) {
                            top.refreshTabByName("每周五销售预测", "no");
                            top.closeTabByPageId("xsyc");
                        })
                    ;
                } else {
                    that.copierReturn();
                    return;
                }
            },
            copierReturn: function () {
                var that = this;
                top.$.dialog({
                    content: 'url:/page/reportForm/salesForecastReport/copierReturnReason.html?id=' + that.main.id + "&pageType=1" + "&t=" + new Date(),
                    title: '填写驳回原因',
                    width: 300,
                    height: 200,
                    max: false,
                    min: false,
                    lock: true
                });
            }
        },

        mounted: function () {
            var that = this;
            that.getTreeData();
        }
    });

</script>
</body>
</html>